package com.example.animaldoctor03;
import Modle.disease.Symptoms;




import java.util.ArrayList;

import bingliandshuju.SingleDataofAll;
import commonClass.ADAQuerySymptomsCategorieByAnimalIDActionofgx;
import commonClass.FunctionDispatcher;
import commonClass.RemoteActionsName;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import Modle.disease.ClinicalSymptomsKey;
public class BiaoGuanZhengZhuang extends Activity {


	
	private Button buttonofbiaoguanzhengzhuangdetail1 = null ;
	private ListView listofbiaoguanzhengzhuang =  null ;
	private String animalIDofBGZZ = "" ;
	//private List<Long> lists = new ArrayList<Long>();
	private ArrayList<Object> resultListofBGZZ = null;
	
	private void getshujuofbiaoguangzz(){
		
		Intent intentofbiaoguanzz = getIntent();
		Bundle dataofbiaoguanzz =  intentofbiaoguanzz.getExtras();
		Symptoms  dataduixiang = (Symptoms)dataofbiaoguanzz.getSerializable("shuju");
		animalIDofBGZZ = dataduixiang.getSymptomsID();
	
	}
	private void initElemofBGZZ (){
	setContentView(R.layout.biaoguanzhengzhuangdetail);
		
		listofbiaoguanzhengzhuang = (ListView)findViewById(R.id.listofbiaoguanzhengzhuang);
		buttonofbiaoguanzhengzhuangdetail1 = (Button)findViewById(R.id.buttonofbiaoguanzhengzhuangdetail1);
		
		
		listofbiaoguanzhengzhuang.setItemsCanFocus(true);
		
	}
	
	private ArrayList<Object> assemblyofBGZZ() {

		getshujuofbiaoguangzz();
		ArrayList<Object> list = new ArrayList<Object>();

		list.add(animalIDofBGZZ);
		// Integer i = new Integer(10);
		// list.add(i);

		return list;
	}
	private void bindingofBGZZ(final ArrayList<Object> list){
		
		try{
		final String[] resultofBGZZ = new String[list.size()];
		// list.toArray(new String[list.size()]);
		for (int i = 0; i < list.size(); i++) {
			
			System.out.println("###############  of  this  " +  ((ClinicalSymptomsKey)list.get(i)).getClinicalSymptomsKey() + "88888");
			
			//haiyouwenti
			resultofBGZZ[i] =((ClinicalSymptomsKey)list.get(i)).getClinicalSymptomsKey() ;
		}
		ArrayAdapter<String> arrayAdapterofResult = new ArrayAdapter<String>(
				this, android.R.layout.simple_list_item_multiple_choice, resultofBGZZ);
		listofbiaoguanzhengzhuang.setAdapter(arrayAdapterofResult);
		
		
	
		
		 listofbiaoguanzhengzhuang.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> parent, View view, int position,
						long id) {
					// TODO Auto-generated method stub


				}
			 
	

			 
		 });
		 buttonofbiaoguanzhengzhuangdetail1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				 ArrayList<Object> listofnext = new ArrayList <Object>();
				
				for(long ids :listofbiaoguanzhengzhuang.getCheckItemIds() ){
					
				int i = (int) ids;
					
					listofnext.add((ClinicalSymptomsKey)list.get(i));
				
				}
				if(listofnext.size() > 0)
				{
				//把数据储存好
				SingleDataofAll singleDataofAll2 = SingleDataofAll.getInstance();
				singleDataofAll2.setListinformation(listofnext);
				
				Bundle bundlleofBGZZ = new Bundle();
				bundlleofBGZZ.putSerializable("shuju", listofnext);
				Intent intentofBGZZ = new Intent(BiaoGuanZhengZhuang.this , AllIllness.class);
				intentofBGZZ.putExtras(bundlleofBGZZ);
				startActivity(intentofBGZZ);
				finish();
				}
				else{
					android.app.AlertDialog.Builder builder = new AlertDialog.Builder(BiaoGuanZhengZhuang.this);
					builder.setMessage("请选择可能症状");
					builder.create().show();
				}
				
			}
		});
		}catch(NullPointerException e){
			android.app.AlertDialog.Builder builderofBGZZ = new AlertDialog.Builder(BiaoGuanZhengZhuang.this);
			builderofBGZZ.setMessage("无数据，请用其他功能");
			builderofBGZZ.create().show();
		}
		 
		 
		
	}	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	
		initElemofBGZZ ();
	
		ArrayList<Object> parasListofBGZZ = assemblyofBGZZ();
		
		final ArrayList<Object> resultListTofBGZZ = null;
		
		
		
		ADAQuerySymptomsCategorieByAnimalIDActionofgx iActionofBGZZ = new ADAQuerySymptomsCategorieByAnimalIDActionofgx();
		FunctionDispatcher functionDispacherofBGZZ = new FunctionDispatcher();
		functionDispacherofBGZZ.exceute(RemoteActionsName.QuerySymptomsByMainSymptomsAction, parasListofBGZZ, iActionofBGZZ, new IRequestCompeletListener() {

			@Override
			public void doCompelet(ArrayList<Object> resultList) {
				// TODO Auto-generated method stub
				try{
				Log.v("ZhengZhuangFZ2", "post:" + resultList.toString());
				BiaoGuanZhengZhuang.this.resultListofBGZZ = resultList;
				bindingofBGZZ(resultList);
			}catch(NullPointerException e){
				android.app.AlertDialog.Builder builderofBGZZf = new AlertDialog.Builder(BiaoGuanZhengZhuang.this);
				builderofBGZZf.setMessage("无数据,请用其他功能");
				builderofBGZZf.create().show();
			}
				}
		},this);

		
	}


	public Handler handler = new Handler() {
		 public void handleMessage(Message msg) {
			 switch (msg.what) {
			 case 1:
				 listofbiaoguanzhengzhuang.setItemChecked((msg.arg1), true);

				 break;
			 }
			 super.handleMessage(msg);
		 }
	};
	

	}
	

	
	
